import 'dart:async';
import 'package:flutter/services.dart';

class WifiStatusPlugin {
  static const MethodChannel _channel = MethodChannel('WifiStatusChannel');

  /// 检查并申请精确位置权限
  static Future<bool> checkAndRequestPermission() async {
    return await _channel.invokeMethod('checkAndRequestPermission');
  }

  /// 判断 WiFi 是否开启
  static Future<bool> isWifiEnabled() async {
    return await _channel.invokeMethod('isWifiEnabled');
  }

  /// 打开 WiFi 设置页，引导用户手动开启 WiFi
  static Future<void> openWifiSettings() async {
    await _channel.invokeMethod('openWifiSettings');
  }

  static Future<String?> getCurrentLocation() async {
    try {
      return await _channel.invokeMethod('getCurrentLocation');
    } on PlatformException catch (e) {
      return "错误: ${e.code} - ${e.message}";
    }
  }
  static Future<List<Map<String, dynamic>>> getWifiList() async {
    final List<dynamic> result = await _channel.invokeMethod('getWifiList');
    return result.cast<Map>().map((e) => Map<String, dynamic>.from(e)).toList();
  }

}
